<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>半实物装备信息编辑</title>
	<meta name="description" content="试验装备管理软件">
	<!-- Bootstrap CSS -->
	<link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
	<!-- 字体CSS -->
	<link href="assets/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
	<!-- 自定义样式 -->
	<link href="assets/css/style.css" rel="stylesheet" type="text/css" />

	<link href="assets/plugins/datetimepicker/css/daterangepicker.css" rel="stylesheet" />
	<link rel="stylesheet" href="./assets/layui/css/layui.css">
	<style>
		.parsley-error {
			border-color: #ff5d48 !important;
		}

		.parsley-errors-list.filled {
			display: block;
		}

		.parsley-errors-list {
			display: none;
			margin: 0;
			padding: 0;
		}

		.parsley-errors-list>li {
			font-size: 12px;
			list-style: none;
			color: #ff5d48;
			margin-top: 5px;
		}

		.form-section {
			padding-left: 15px;
			border-left: 2px solid #FF851B;
			display: none;
		}

		.form-section.current {
			display: inherit;
		}

		body {
			padding-bottom: 0;
		}

		.card-height .form-group {
			margin-top: 40px;
		}

		.card-height .form-group:first-of-type {
			margin-top: 0;
		}
		/* 新增样式 */
		.sub-text{
			color:#95a1ab;
		}
		.content-right .form-group label{
			text-align: left;
			margin-left: 10px;
		}
		.layui-table-tool button{
			color:#95a1ab;
			background: #343f67;
		}
		.content-page .content{
			background: #212948;
			padding-top: 15px;
			margin: 70px 15px 15px 15px;
		}
		.layui-table-tool>.layui-table-tool-temp{
			padding-right: 0;
		}
		.table-tool-left{
			float: left;
		}
		.table-tool-right{
			float: right;
		}
		.table-content .layui-table-tool{
			background: #212948;
		}
		.table-content .layui-table thead tr{
			background: #212948;
		}
		.table-content .layui-table th,.table-content .layui-table-view{
			border:none;
		}
		.table-content .layui-table-view .layui-table{
			width:100%;
		}
		.table-content .layui-table-page a,.table-content .layui-table-page em{
			color:#95a1ab;
		}
		.table-content .layui-table-page span.layui-laypage-count {
			color:#95a1ab;
		}
		.table-content .layui-laypage .layui-laypage-curr .layui-laypage-em{
			background-color:#0199f2;
		}
		.table-content .layui-table tr{
			background:#212948;
			border-bottom: #343f67 solid 1px;
		}
		.table-content .layui-table td{
			border:none;
		}
		.table-content .layui-table-page,.table-content .layui-table-header,.table-content .layui-table-tool,.table-content .layui-table-fixed-r{
			border:none;
		}
		.table-content .layui-table tbody tr:hover{
			background: #1c2443;
		}
		.demo-form h6{
			color:#bdd1e1;
			margin: 10px 0px;
			font-size: 16px;
		}
		.useContent .useBox{
			margin:15px;
		}
		.paramContent .paramBox{
			margin:15px;
		}
	</style>
</head>

<body class="adminbody">
<div id="main">
	<!-- 头部导航 -->
	<div class="headerbar">
		<!-- LOGO -->
		<div class="headerbar-left">
			<a href="index.html" class="logo">
				<img alt="Logo" src="assets/images/logo.png" />
				<span>试验资源管理软件</span>
			</a>
		</div>

		<nav class="navbar-custom">
			<ul class="list-inline float-right mb-0">
				<li class="list-inline-item dropdown notif">
					<a class="nav-link dropdown-toggle arrow-none" data-toggle="dropdown" href="#" role="button"
					   aria-haspopup="false" aria-expanded="false">
						<i class="fa fa-fw fa-bell-o"></i><span class="notif-bullet"></span>
					</a>
					<div class="dropdown-menu dropdown-menu-right dropdown-arrow dropdown-lg">
						<!-- item-->
						<div class="dropdown-item noti-title">
							<h5><small><span class="label label-danger pull-xs-right">1</span>消息提醒</small></h5>
						</div>
						<!-- item-->
						<a href="#" class="dropdown-item notify-item">
							<div class="notify-icon bg-faded">
								<img src="assets/images/avatars/avatar2.png" alt="img"
									 class="rounded-circle img-fluid">
							</div>
							<p class="notify-details">
								<b>Admin</b>
								<span>用户信息注册成功</span>
								<small class="text-muted">3分钟前</small>
							</p>
						</a>
						<!-- All-->
						<a href="#" class="dropdown-item notify-item notify-all">
							查看所有消息
						</a>

					</div>
				</li>

				<li class="list-inline-item dropdown notif">
					<a class="nav-link dropdown-toggle nav-user" data-toggle="dropdown" href="#" role="button"
					   aria-haspopup="false" aria-expanded="false">
						<img src="assets/images/avatars/admin.png" alt="Profile image" class="avatar-rounded">
					</a>
					<div class="dropdown-menu dropdown-menu-right profile-dropdown ">
						<!-- item-->
						<div class="dropdown-item noti-title">
							<h5 class="text-overflow"><small>Hello, admin</small> </h5>
						</div>

						<!-- item-->
						<a href="pro-profile.html" class="dropdown-item notify-item">
							<i class="fa fa-user"></i> <span>个人中心</span>
						</a>

						<!-- item-->
						<a href="#" class="dropdown-item notify-item">
							<i class="fa fa-power-off"></i> <span>退出</span>
						</a>
					</div>
				</li>

			</ul>

			<ul class="list-inline menu-left mb-0">
				<li class="float-left">
					<button class="button-menu-mobile open-left">
						<i class="fa fa-fw fa-bars"></i>
					</button>
				</li>
			</ul>

		</nav>

	</div>
	<!-- 头部导航End -->
	<!-- 左侧导航开始 start-->
	<div class="left main-sidebar">
		<div class="sidebar-inner leftscroll">
			<div id="sidebar-menu">
				<ul>
					<li class="submenu">
						<a href="index.html"><i class="fa fa-fw fa-bars"></i><span>首页</span> </a>
					</li>
					<li class="submenu">
						<a href="#" ><i class="fa fa-fw fa-tv"></i> <span>试验资源注册模块</span>
							<span class="menu-arrow"></span>
						</a>
						<ul class="list-unstyled">
							<li><a href="ui-alerts.html">实装信息注册</a></li>
							<li><a href="entityRegister.html">半实物装备信息注册</a></li>
							<li><a href="ui-cards.html">数字仿真模型信息注册</a></li>
							<li><a href="personRegistration.html">人员信息注册</a></li>
							<li><a href="ui-collapse.html">场地信息注册</a></li>
						</ul>
					</li>
					<li class="submenu">
						<a href="#">
							<i class="fa fa-fw fa-table"></i>
							<span> 资源导入导出模块</span>
							<span class="menu-arrow"></span>
						</a>
						<ul class="list-unstyled">
							<li><a href="ui-alerts.html">实装信息</a></li>
							<li><a href="ui-buttons.html">半实物装备信息</a></li>
							<li><a href="ui-cards.html">数字仿真模型信息</a></li>
							<li><a href="ui-carousel.html">人员信息</a></li>
							<li><a href="ui-collapse.html">场地信息</a></li>
						</ul>
					</li>
					<li class="submenu active">
						<a href="#" class='active'><i class="fa fa-fw fa-file-text-o"></i> <span>试验资源编辑模块</span>
							<span class="menu-arrow"></span>
						</a>
						<ul class="list-unstyled">
							<li><a href="ui-alerts.html">实装信息编辑</a></li>
							<li class="active"><a href="entityEdit.html">半实物装备信息编辑</a></li>
							<li><a href="ui-cards.html">数字仿真模型信息编辑</a></li>
							<li><a href="ui-carousel.html">人员信息编辑</a></li>
							<li><a href="ui-collapse.html">场地信息编辑</a></li>
						</ul>
					</li>
					<li class="submenu">
						<a href="#">
							<i class="fa fa-fw fa-th"></i>
							<span>综合资源查询模块 </span>
							<span class="menu-arrow"></span>
						</a>
						<ul class="list-unstyled">
							<li><a href="ui-alerts.html">实装信息查询</a></li>
							<li><a href="ui-buttons.html">半实物装备信息查询</a></li>
							<li><a href="ui-cards.html">数字仿真模型信息查询</a></li>
							<li><a href="ui-carousel.html">人员信息查询</a></li>
							<li><a href="ui-collapse.html">场地信息查询</a></li>
						</ul>
					</li>
					<li class="submenu">
						<a href="javascript:;">
							<i class="fa fa-fw fa-area-chart"></i>
							<span> 试验资源监视模块 </span>
							<span class='menu-arrow'></span>
						</a>
						<ul class="list-unstyled">
							<li><a href="ui-alerts.html">实装信息监视</a></li>
							<li><a href="ui-buttons.html">半实物装备信息监视</a></li>
							<li><a href="ui-cards.html">数字仿真模型信息监视</a></li>
							<li><a href="ui-carousel.html">人员信息监视</a></li>
							<li><a href="ui-collapse.html">场地信息监视</a></li>
						</ul>
					</li>
				</ul>
				<div class="clearfix"></div>
			</div>
			<div class="clearfix"></div>

		</div>

	</div>
	<!-- End 左侧导航 -->
	<div class="content-page">
		<!-- Start content -->
		<!-- 数据表 -->
		<div class="content table-content">
			<table class="layui-hide" id="test" lay-filter="test"></table>
		</div>
	</div>
</div>
<!-- 左边工具栏 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<div class="table-tool-left">
			<button class="layui-btn " lay-event="getInputData" style="font-size:16px;" id="fileUpload">
				<img src="./assets/images/img/import.png" alt="">
				导入
			</button>
			<button class="layui-btn" lay-event="getOutputData" style="font-size:16px;">
				<img src="./assets/images/img/export.png" alt="">
				导出
			</button>
		</div>
		<div class="table-tool-right">
			<button class="layui-btn " lay-event="getDeleteData" style="font-size:16px;">
				<img src="./assets/images/img/delete.png" alt="">
			</button>
			<button class="layui-btn" lay-event="getCopyLength" style="font-size:16px;">
				<img src="./assets/images/img/copy.png" alt="">
			</button>
			<button class="layui-btn" lay-event="saveData" style="font-size:16px;">
				<img src="./assets/images/img/save.png" alt="">
			</button>
		</div>
	</div>
</script>
<!-- 右边工具栏 -->
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-xs" lay-event="edit" style="color:#fff;background: #0199f2;">编辑</a>
</script>
<script type="text/html" id="useEdit">
	<a class="layui-btn layui-btn-xs" lay-event="useEdit" style="color:#fff;background: #0199f2;">查看</a>
</script>
<script type="text/html" id="paramEdit">
	<a class="layui-btn layui-btn-xs" lay-event="paramEdit" style="color:#fff;background: #0199f2;">查看</a>
</script>


<script src="./assets/layui/layui.js"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->
<script src="assets/js/modernizr.min.js"></script>
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/moment.min.js"></script>
<script src="assets/js/popper.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>


<script src="assets/js/detect.js"></script>
<script src="assets/js/fastclick.js"></script>
<script src="assets/js/jquery.blockUI.js"></script>
<script src="assets/js/jquery.nicescroll.js"></script>

<!-- App js -->
<script src="assets/js/pikeadmin.js"></script>
<!-- 验证表单 -->
<script src="assets/plugins/parsleyjs/parsley.min.js"></script>
<script src="assets/plugins/datetimepicker/js/moment.min.js"></script>
<script src="assets/plugins/datetimepicker/js/daterangepicker.js"></script>

<script>
	var equipmentId=1,layer,eqId;//装备id,此处将来需要改动
	var dateRange=``,paramArr=["name","type","number","unit","forces","inParam","outParam","state","address","matchableModel"],editId;
	layui.use('layer', function(){
		layer=layui.layer;
	});
	layui.use('table', function(){
		var table = layui.table;
		table.render({
			elem: '#test',
			url:'/rm/hard/findAllHardWare',
			method:'post'
			//,contentType: 'application/json'
			,where:{equipmentId}
			,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
			,defaultToolbar: []
			,skin:'nob'
			,title: '用户数据表'
			,cols: [[
				{type: 'checkbox', fixed: 'left'}
				// ,{field:'id', title:'ID',  fixed: 'left', width:60,unresize: true,align:'center'}
				,{field:'sort', title:'序号', width:60,unresize: true,align:'center',type:'numbers'}
				,{field:'name', title:'名称', }
				,{field:'type', title:'类型'}
				,{field:'number', title:'装备编号',}
				,{field:'unit', title:'研制单位', }
				,{field:'forces', title:'所属部队'}
				,{field:'parameters', title:'输入/输出参数',toolbar: '#paramEdit',align:'center'}
				,{field:'useInfo', title:'使用信息', toolbar: '#useEdit',align:'center'}
				,{fixed: 'right', title:'操作', toolbar: '#barDemo',align:'center'}
			]]
			,page: {
				layout: [ 'prev', 'page', 'next', 'count', 'skip']//自定义分页布局
				,limit:10
				// ,limits:[3,6,9]
				,first: false //不显示首页
				,last: false //不显示尾页
			}
			,request: {
				pageName: 'currentPage' //页码的参数名称，默认：page
				,limitName: 'pageSize' //每页数据量的参数名，默认：limit
			}
			,parseData: function(res){ //res 即为原始返回的数据
				return {
					"code": res.status, //解析接口状态
					"msg": res.msg, //解析提示文本
					"count": res.data.totalCount, //解析数据长度
					"data": res.data.lists //解析数据列表
				};
			}
	});
		//头工具栏事件
		table.on('toolbar(test)', function(obj){
			var checkStatus = table.checkStatus(obj.config.id);
			var checkData = checkStatus.data,checkArr=[];
			console.log(checkData)
			//数据id 获取
			if (checkData.length>0){
				for (let i of  checkData){
					checkArr.push(i.id);
				}
			}
			//工具栏
			switch(obj.event){
				case 'getInputData':
                    var input=document.createElement('input');
                    input.setAttribute('type', 'file');
                    input.setAttribute('accept', 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                    input.click();
                    input.onchange=function (e) {
                        handleFile(input.files[0]);
                    }
					break;
				case 'getOutputData':
					var a=document.createElement('a');
					a.setAttribute('download', '');// download属性
					a.setAttribute('href', '/rm/hard/export');// href链接
					a.click();
					break;
				case 'getDeleteData':
					if (checkArr.length>0){
						layer.confirm('确认要删除吗？', {
							btn: ['确认','取消'] //按钮
						}, function(){
							$.ajax({
								//请求方式
								type : "POST",
								//请求的媒体类型
								// contentType: "application/json",
								//请求地址
								url : "/rm/hard/removeHardWareById",
								//数据，json字符串
								data : {'ids':checkArr.join(',')},
								// data : JSON.stringify(ids:checkArr.join(',')),
								//请求成功
								success : function(res) {
									if (res.status==0){
										layer.msg('删除成功！',{time:2000});
										//刷新数据
										$(".layui-laypage-btn")[0].click();
									}else {
										layer.msg('删除失败！',{time:2000});
									}
								},
								//请求失败，包含具体的错误信息
								error : function(e){
									console.error(e.status);
									console.error(e.responseText);
								}
							});
						});
					}


					break;
				case 'getCopyLength':
                    if (checkArr.length>0){
                        layer.confirm('确认要复制所选内容吗？', {
                            btn: ['确认','取消'] //按钮
                        }, function(){
                            $.ajax({
                                //请求方式
                                type : "POST",
                                //请求的媒体类型
                                // contentType: "application/json",
                                //请求地址
                                url : "/rm/hard/copyHardWare",
                                //数据，json字符串
                                data : {'ids':checkArr.join(',')},
                                //请求成功
                                success : function(res) {
                                    if (res.status==0){
                                        layer.msg('复制成功！',{time:2000});
                                        //刷新数据
                                        $(".layui-laypage-btn")[0].click();
                                    }else {
                                        layer.msg('复制失败！',{time:2000});
                                    }

                                },
                                //请求失败，包含具体的错误信息
                                error : function(e){
                                    console.error(e.status);
                                    console.error(e.responseText);
                                }
                            });
                        })
                    }


					break;
				case 'saveData':
					layer.msg('保存');
					break;
			};
		});

		//监听行工具事件
		table.on('tool(test)', function(obj){
			var data = obj.data;
				editId=data.id;
				eqId=data.equipmentId;
			if(obj.event === 'edit'){
                $.ajax({
					//请求方式
					type : "POST",
					//请求的媒体类型
					// contentType: 'x-www-form-urlencoded',
					//请求地址
					url : "/rm/hard/findHardWareById",
					//数据，json字符串
					data : {'id':editId},
					//请求成功
					success : function(res) {
						console.log(layer);
						if (res.status==0){
							handleEdit(res.data)
						}else {
							layer.msg('打开失败！')
						}

					},
					error : function(e){
						console.error(e.status);
						console.error(e.responseText);
					}
				});
			}else if (obj.event=='useEdit'){
				console.log(data.useInfos)
				layer.open({
					type: 1 //Page层类型
					,area: ['700px', '400px']
					,title: false
					,shade: 0.4 //遮罩透明度
					,maxmin: false //允许全屏最小化
					,anim: 1 //0-6的动画形式，-1不开启
					,content: `
							<div class="useContent">
								<div class="useBox">
									<table class="layui-hide" id="useTable" lay-filter="useTable"></table>
								</div>
							</div>`
					,success: function(Layer, index){
						var useTable=table.render({
							elem: '#useTable',
							url:''
							,toolbar: '' //开启头部工具栏，并为其绑定左侧模板
							// ,skin:'row'
							,title: '用户数据表'
							,data:data.useInfos
							,cols: [[
								{field:'sort', title:'序号', width:60,unresize: true,align:'center',type:'numbers'}
								,{field:'state', title:'使用状态', edit:'text',align:'center'}
								,{field:'address', title:'使用地点',edit:'text',align:'center'}
								,{field:'startTime', title:'开始时间',edit:'text',align:'center' }
								,{field:'endTime', title:'结束时间',edit:'text',align:'center' }
							]]
							// ,page: {
							// 	layout: [ 'prev', 'page', 'next', 'count', 'skip']//自定义分页布局
							// 	,limit:10
							// 	// ,limits:[3,6,9]
							// 	,first: false //不显示首页
							// 	,last: false //不显示尾页
							// }
							,cancel: function(index, layero){
								layer.close(index);
								table.render();
							}
						});
					//
						table.on('edit(useTable)', function (obj) {
							var value = obj.value;//修改后的数据
							var field = obj.field;//修改的字段名
							var data = obj.data;//修改的当行数据
							//获取修改行的ID值
							console.log(obj)
							$.ajax({
								//请求方式
								type : "post",
								//请求的媒体类型
								contentType: "application/json",//x-www-form-urlencoded
								//请求地址
								url : "/rm/hard/editUseInfoById",
								//数据，json字符串
								data : JSON.stringify(data),
								//请求成功
								success : function(res) {
									if (res.status==0){
										layer.closeAll();
										// table.reload();
										layer.msg('修改成功！',{time:2000});
									}else {
										layer.msg('修改失败！',{time:2000});
									}
								},
								error : function(e){
									console.error(e.status);
									console.error(e.responseText);
								}
							});
						});

					}
				});
			}else if (obj.event=='paramEdit'){
				layer.open({
					type: 1 //Page层类型
					,area: ['700px', '400px']
					,title: false
					,shade: 0.4 //遮罩透明度
					,maxmin: false //允许全屏最小化
					,anim: 1 //0-6的动画形式，-1不开启
					,content: `
							<div class="paramContent">
								<div class="paramBox">
									<table class="layui-hide" id="paramTable" lay-filter="paramTable"></table>
								</div>
							</div>`
					,success: function(layer, index){
						var paramTable=table.render({
							elem: '#paramTable',
							url:''
							,toolbar: '' //开启头部工具栏，并为其绑定左侧模板
							// ,skin:'row'
							,title: '用户数据表'
							,data:data.performances
							,cols: [[
								{field:'sort', title:'序号', width:60,unresize: true,align:'center',type:'numbers'}
								,{field:'performanceName', title:'性能名称', edit:'text',align:'center'}
								,{field:'performanceValue', title:'性能单位',edit:'text' ,align:'center'}
							]]
							// ,page: {
							// 	layout: [ 'prev', 'page', 'next', 'count', 'skip']//自定义分页布局
							// 	,limit:10
							// 	// ,limits:[3,6,9]
							// 	,first: false //不显示首页
							// 	,last: false //不显示尾页
							// }
						});
						//
						table.on('edit(paramTable)', function (obj) {
							var value = obj.value;//修改后的数据
							var field = obj.field;//修改的字段名
							var data = obj.data;//修改的当行数据
							//获取修改行的ID值
							console.log(obj)
						});

					}
				});
			}
		});
	});

	//文件上传
	function handleFile(file){
		var formData=new FormData();
			formData.append('file',file);
			$.ajax({
			//请求方式
			type : "post",
			//请求的媒体类型
			contentType: false,
            processData: false,
			//请求地址
			url : "/rm/hard/import",
			//数据，json字符串
			data : formData,
			//请求成功
			success : function(res) {
				if (res.status==0){
					layer.msg('上传成功！',{time:2000});
				}else {
					layer.msg('上传失败！',{time:2000});
				}
			},
			error : function(e){
				console.error(e.status);
				console.error(e.responseText);
			}
		});
	}
//	编辑
    function handleEdit(data){
        layer.open({
            type: 1 //Page层类型
            ,area: ['1400px', '700px']
            ,title: false
            ,shade: 0.4 //遮罩透明度
            ,maxmin: false //允许全屏最小化
            ,anim: 1 //0-6的动画形式，-1不开启
            ,content: `
                <div class="content-page" style="margin-left:0;background:#212948;">
			        <!-- Start content -->
			        <div class="content" style="margin-top: 20px;">
						<div class="row">
							<div class="col-xs-12 col-sm-12 col-md-5 col-lg-5 col-xl-5">
								<div class="card mb-3">
									<div class="card-header">
										<h3>
											<!-- 缺图标 -->
											<!-- <i class="fa fa-user"></i> -->
											半实物装备列表修改
										</h3>
									</div>
									<div class="card-body" style='height:500px;'>
										<form action="#" data-parsley-validate novalidate>
											<div class="form-group">
												<label for="name">名称<span class="text-danger">*</span></label>
												<input type="text" name="name" data-parsley-trigger="change" required
													   placeholder="请输入名称" class="form-control" id="name">
											</div>
											<div class="form-group">
												<label for="type">类型<span class="text-danger">*</span></label>
												<input type="text" name="type" data-parsley-trigger="change" required
													placeholder="请输入类型" class="form-control" id="type">
											</div>
											<div class="form-group">
												<label for="number">编号<span class="text-danger">*</span></label>
												<input type="text" name="number" data-parsley-trigger="change" required
													placeholder="请输入编号" class="form-control" id="number">
											</div>
											<div class="form-group">
												<label for="temName">仿真名称/仿真模型
													<span class="text-danger">*</span>
												</label>
												<select required class="form-control" id="temName">
													<option value="">请选择</option>
													<option value="一">一</option>
													<option value="二">二</option>
													<option value="三">三</option>
												</select>
											</div>
											<div class="form-group">
												<label for="unit">研制单位
													<span class="text-danger">*</span>
												</label>
												<select required class="form-control" id="unit">
													<option value="">请选择</option>
													<option value="单位一">单位一</option>
													<option value="单位二">单位二</option>
													<option value="单位三">单位三</option>
												</select>
											</div>
											<div class="form-group">
												<label for="forces">所属部队
													<span class="text-danger">*</span>
												</label>
												<select required class="form-control" id="forces">
													<option value="">请选择</option>
													<option value="部队一">部队一</option>
													<option value="部队二">部队二</option>
													<option value="部队三">部队三</option>
												</select>
											</div>

											<div class="form-group">
												<label for="matchableModel">可匹配模型
													<span class="text-danger">*</span>
												</label>
												<select required class="form-control" id="matchableModel">
													<option value="">请选择</option>
													<option value="一">一</option>
													<option value="二">二</option>
													<option value="三">三</option>
												</select>
											</div>
										</form>
									</div>
								</div><!-- end card-->
							</div>

							<div class="col-xs-12 col-sm-12 col-md-7 col-lg-7 col-xl-7">
								<div class="card mb-3 content-right">
									<div class="card-header">
										<h3>
											<!-- <i class="fa fa-hand-pointer-o"></i> -->
											信息修改</h3>
									</div>
									<div class="card-body card-height" style='height:500px;'>
								<form class="demo-form" action="#">
									<div id="mainPerformance">
										<h6 class="">主要性能:</h6>
										<div class="row" style="justify-content: space-between;height: 135px;overflow: auto;">
										</div>
									</div>
									<div id="mainPar">
										<h6 class="">输入输出接口参数:</h6>
										<div class="row" style="justify-content: space-around;">
											<div class=" col-md-6 col-lg-6">
												<div class="form-group">
													<label for="inParam">输入接口</label>
													<input type="text" name="inParam" placeholder="请填写输入接口" class="form-control"
														   id="inParam">
												</div>
											</div>
											<div class=" col-md-6 col-lg-6">
												<div class="form-group">
													<label for="outParam">输出接口</label>
													<input type="text" name="outParam" placeholder="请填写输出接口" class="form-control"
														   id="outParam">
												</div>
											</div>
										</div>
									</div>

									<div id="stateInfo">
										<h6 class="">使用信息:</h6>
										<div class="row">
											<div class="layui-col-xs6">
												<div class="form-group">
													<label for="state">状态信息
														<span class="text-danger">*</span>
													</label>
													<input type="text" name="state" data-parsley-trigger="change" required
														   placeholder="请输入状态信息" class="form-control" id="state">
												</div>
											</div>
											<div class="layui-col-xs6">
												<div class="form-group">
													<label for="address">使用地点</label>
													<input type="text" name="address" placeholder="请输入使用地点" class="form-control"
														   id="address">
												</div>
											</div>
											<div class="layui-col-xs6">
												<div class="layui-form" >
													<div class="layui-form-item" >
														<label class="layui-form-label" style="width: 24%;text-align: left;color: #95a1ab;font-size: 1rem;">日期范围</label>
														<div class="layui-input-inline " style="width: 76%; margin-right: 0px;">
															<input type="text" class="layui-input form-control" id="test6" placeholder="请选择日期范围"
																   style="background:#343f67;border-radius: 4px;border:none;">
														</div>
													</div>
												</div>
											</div>


										</div>
									</div>
								</form>
							</div>
								</div>
							</div>
							<div class="form-group col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6" style='margin: 20px auto'>
								<button class="btn btn-primary btn-size col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6"
									type="submit" onclick="handleSubmit()" style="margin-left:80px;margin-top: 20px;">
									提交
								</button>
							</div>
						</div>
					</div>
                </div>`
            ,success: function(layer, index){
				var paramObj={},inpVal='',dateObj,obj,str='';
				for (let i of paramArr){
					$(`#${i}`).val(data[i]);
				}
				//	主要性能获取
				for (let k of data.performances){
					console.log(k.performanceId)
					str+=`<div class="col-xs-4">
						<div class="form-group">
							<label  style="margin-left: 20px;">${k.performanceName}</label>
							<input type="text"   class="form-control" value=${k.performanceValue? k.performanceValue:''} data-id=${k.performanceId}>
						</div>
					 </div>`;

				}
				var ele=$(".content-right form .row:first-child ");
				ele.append(str);
				//日期默认值
				dateRange=`${data.startTime} - ${data.endTime}`
				layui.use('laydate', function(){
					var laydate = layui.laydate;
					laydate.render({
						elem: '#test6'
						,range: true
						,value: `${data.startTime} - ${data.endTime}` //必须遵循format参数设定的格式
						,done: function(value, date, endDate){
							console.log(value); //得到日期生成的值，如：2017-08-18
							dateRange=value;
							console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
							console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
						}
					});
				})

            }
        });
    }
//    提交
	function handleSubmit() {
		var paramObj={},inpVal='',dateObj,obj;
		var arr=[],startDate,endDate,dataArr=dateRange?dateRange.split(' '):['','',''];
		for (let i of paramArr){
			inpVal=document.getElementById(i).value;
			if (i=="matchableModel"){
				paramObj[i]="1,2";//可匹配模型 暂时传 "1,2"
			}else {
				paramObj[i]=inpVal;
			}
		}
		//	主要性能获取
		var propertyArr=$("#mainPerformance .col-xs-4 .form-group");
		for (let k=0;k<propertyArr.length;k++){
			var eve=propertyArr[k]
			var performanceName=$(eve).children('label').text();
			var performanceValue=$(eve).children('input').val();
			var performanceId=$(eve).children('input').attr('data-id');
			arr.push({performanceId,performanceValue,performanceName});
		}
		//日期范围获取
		startDate=dataArr[0];
		endDate=dataArr[2];
		dateObj={ startTime:startDate,endTime:endDate,performances:arr}
		obj=Object.assign(paramObj,dateObj,{id:editId,equipmentId:eqId})
		console.log(obj)
		//
		$.ajax({
			//请求方式
			type : "POST",
			//请求的媒体类型
			contentType: "application/json",
			//请求地址
			url : "/rm/hard/editHardWareById",
			//数据，json字符串
			data : JSON.stringify(obj),
			//请求成功
			success : function(res) {
				console.log(res);
				if (res){
					layer.closeAll();
					layer.msg('修改成功！',{time:2000});
					//刷新数据
					$(".layui-laypage-btn")[0].click();

				}else {
					layer.msg('修改失败！',{time:2000});
				}

			},
			//请求失败，包含具体的错误信息
			error : function(e){
				console.error(e.status);
				console.error(e.responseText);
			}
		});
	}
</script>
</body>

</html>